<?php

/**
 * @author Anh Nguyen <duyanhnguyen@vccorp.vn>
 * @copyright 2012
 */

class Banner_model extends CI_Model
{

    function __construct()
    {
        parent::__construct();
    }
    
    public function getBannerOntion()
    {
        $return = array();
        $this->db->select('*')
                ->from('options');
        $rs = $this->db->get();
        $return = $rs->result_array();
        $rs->free_result();
        return $return;
    }
     public function updateNameGroup($Id, $data = array())
    {
          if (!is_null($data)) {
            $result = $this->db->update('list_group', $data, array(
                'id'    =>  $Id,
            ));
            return true;
        }
        return false;
         
           
    }
    
    public function updatePriceGroup($typeGroup , $Id, $price_update)
    {
        $sql = "UPDATE `item_sim` SET `price` = `price_update`, `price_update` = `price_update` + $price_update WHERE $typeGroup = $Id";
        if($this->db->query($sql))
            return true;    
        return false;
    }
    
    public function deleteNameGroup($Id)
    {
        $this->db->delete('list_group', array('id' => $Id));   
    }

    public function updateNameGroupDeleteF($Id, $data = array())
    {
        if (!is_null($data)) {
            $this->db->update('list_group', $data, array(
                'id' => $Id
            ));
        }
    }
    
    public function groupExists($name)
    {
        $this->db->select('*');
        $this->db->from('list_group');
        $this->db->where('name', $name);
        $rs = $this->db->get();
        $return = ($rs->num_rows() > 0) ? true : false;
        $rs->free_result();
        return $return;
    }
    
    public function checkGroupExists($list_group_id)
    {
        $this->db->select('*')
                ->from('list_group')
                ->where('id', $list_group_id);
        $rs = $this->db->get();
        $return = ($rs->num_rows() > 0) ? true : false;
        $rs->free_result();
        return $return;
    }
    
    public function addNameGroup($name)
    {
        $array = array(
//            'parent_id' => $parent_id,
            'name' => $name,
//            'name_en' => $name_en,
//            'href' => $href,
            'delete_flag' => '0'
        );
        return $this->db->insert('list_group', $array);
    }
    
    public function addGroupBatch($data) {
        return $this->db->insert_batch('list_group', $data);
    }
}

?>
